using System.Collections.Generic;
using System.Drawing;
using System.Text;
using Lib.Controls;

namespace DataStubGenerator.Controls
{
    public class SqlModel
    {
        private string[] _sql;
        public string[] Sql
        {
            get { return _sql; }
            set { _sql = value;
            }
        }


        #region Stuff needed for syntax highlighting
        
        private readonly List<string> _sqlKeywords =
            new List<string>(new string[] { "select", "from", "where" });

        private readonly List<string>  _greyOutWords = 
            new List<string>(new string[] {"*","union"});

        public List<Highlight> GetAllKeywordHighlights()
        {
            return GetHighlights(_sqlKeywords);
        }

        private List<Highlight> GetHighlights(List<string> keywords)
        {
            GetHighlightsCommand cmd = new GetHighlightsCommand(this, keywords);
            cmd.Execute();
            return cmd.Highlights;
        }

        public List<Highlight> GetGreyWordHighlights()
        {
            GetHighlightsCommand cmd = new GetHighlightsCommand(this, _greyOutWords);
            cmd.Execute();
            return cmd.Highlights;
        } 

        public Color GetHighlightColor(string keyword) {
            Color highlight;
            
            if (_sqlKeywords.Contains(keyword.ToLower())) highlight = Color.Blue;
            else highlight = SystemColors.GrayText;
            return highlight;
        }
        #endregion

        string GetSqlString()
        {
            StringBuilder sqlBuilder = new StringBuilder();

            foreach (string sqlLine in _sql) {
                sqlBuilder.Append(sqlLine);
                if (!sqlLine.EndsWith(" "))
                    sqlBuilder.Append(" ");
            }
            return sqlBuilder.ToString();
        }


    }
}
